﻿using IDAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata.Ecma335;
using System.Text;
using System.Threading.Tasks;
using Web.IBLL;
using Web.Model;

namespace Web.BLL
{
    public class RoomBLL : IRoomBLL
    {
        public RoomBLL(IBaseDAL<Room> dAL)
        {
            DAL = dAL;
        }

        public IBaseDAL<Room> DAL { get; }

        

        public Task<int> RAdd(Room r)
        {
            return DAL.AddAsync(r);
        }

        

        public dynamic RShow(int Pageindex, int Pagesize)
        {
            var list = DAL.GetAll().Where(x => x.IsDelete == true);
            var c = list.Count();
            var d = list.OrderBy(x => x.Id).Skip((Pageindex - 1) * Pagesize).Take(Pagesize).ToList();
            return new
            {
                count = c,
                list= d
            };
        }
        public Task<int> RDel(int Id)
        {
            var list = DAL.GetAll().FirstOrDefault(x => x.Id == Id);
            list.IsDelete =false;
            return DAL.UpdAsync(list);
        }
        public Room Fan(int Id)
        {
            return DAL.GetAll().FirstOrDefault(x => x.Id == Id);
        }
        public Task<int> Upd(Room r)
        {
            return DAL.UpdAsync(r);
        }
    }
}
